# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>

# The group tag is just to easily find this APKBUILD by some scripts for automation
# group=qt6
pkgname=qt6-qtmultimedia
pkgver=6.7.2
pkgrel=0
pkgdesc="Classes for audio, video, radio and camera functionality"
url="https://qt.io/"
arch="all"
license="LGPL-2.1-only AND LGPL-3.0-only AND GPL-3.0-only AND Qt-GPL-exception-1.0"
depends_dev="
	$pkgname-ffmpeg=$pkgver-r$pkgrel
	$pkgname-gstreamer=$pkgver-r$pkgrel
	alsa-lib-dev
	ffmpeg-dev
	gst-plugins-base-dev
	gstreamer-dev
	libva-glx-dev
	pulseaudio-dev
	qt6-qtbase-dev
	qt6-qtdeclarative-dev
	qt6-qtshadertools-dev
	qt6-qtsvg-dev
	"
makedepends="$depends_dev
	cmake
	perl
	samurai
	"
subpackages="
	$pkgname-dev
	$pkgname-ffmpeg
	$pkgname-gstreamer
	"

case $pkgver in
	*_alpha*|*_beta*|*_rc*) _rel=development_releases;;
	*) _rel=official_releases;;
esac

source="https://download.qt.io/$_rel/qt/${pkgver%.*}/${pkgver/_/-}/submodules/qtmultimedia-everywhere-src-${pkgver/_/-}.tar.xz
	select.patch
	"
options="!check" # Tests don't run
builddir="$srcdir/qtmultimedia-everywhere-src-${pkgver/_/-}"

build() {
	# alsa disabled due to build failure for now
	# src/multimedia/platform/alsa/qalsaaudiosink.cpp:270:5: error: 'timeStamp' was not declared in this scope
	export CFLAGS="$CFLAGS -g1 -flto=auto"
	export CXXFLAGS="$CXXFLAGS -g1 -flto=auto"
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DINSTALL_BINDIR=lib/qt6/bin \
		-DINSTALL_DOCDIR=share/doc/qt6 \
		-DINSTALL_ARCHDATADIR=lib/qt6 \
		-DINSTALL_DATADIR=share/qt6 \
		-DINSTALL_INCLUDEDIR=include/qt6 \
		-DINSTALL_MKSPECSDIR=lib/qt6/mkspecs \
		-DINSTALL_EXAMPLESDIR=share/doc/qt6/examples \
		-DQT_FEATURE_alsa=OFF \
		-DQT_FEATURE_pulseaudio=ON
	cmake --build build --parallel
}

check() {
	ctest --test-dir build --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

ffmpeg() {
	pkgdesc="$pkgdesc (ffmpeg plugin)"
	# autopull if main dep exists anyway
	install_if="$pkgname=$pkgver-r$pkgrel ffmpeg-libavcodec"

	amove usr/lib/qt6/plugins/multimedia/libffmpegmediaplugin.so
}

gstreamer() {
	pkgdesc="$pkgdesc (gstreamer plugin)"
	# unlike above, these deps are not that obvious.
	# -base is pulled by e.g. gtk4 anyway, but practically nothing
	# would use this unless people added good, etc. so use that
	install_if="$pkgname=$pkgver-r$pkgrel gst-plugins-good"

	amove usr/lib/qt6/plugins/multimedia/libgstreamermediaplugin.so
}

sha512sums="
bfcd04a5ba142e2a3bee3b67a261ffb4f651ac4e043e3dcafc0175bd25409de375041aa6fdda4f6899b00e4bad6c06ae9fd0d6a1e7db0b874f1bcf0a578d3c70  qtmultimedia-everywhere-src-6.7.2.tar.xz
1777a0c30cfa9fbcdcc1cf44e95822c6521b3ba95fb7a49e01a11e8107f24c0850b18fe2ac88fb1c1f88dfc5c2ed4ef17e081ef4e5a3cfbf4fb28c715f3935c5  select.patch
"
